<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<%@page pageEncoding="UTF-8"%>
<%@include file="../WEB-INF/jspf/controlesessao.jspf"%>

<c:catch var ="catchException">
    <fmt:parseDate var="data" value="${param.data_calendario}" pattern="dd/MM/yyyy"/>
    <c:choose>
        <c:when test="${param.oper=='add'}">
            <sql:update var="update" dataSource="jdbc/dbo_MicrosoftSQLServer">
                insert into calendarios (id_turma,id_cidade,diautil_calendario, data_calendario)
                select id_turma, id_cidade, ?, ?
                from turmas
                where id_turma=?
                <sql:param value="${param.diautil_calendario}"/>
                <sql:dateParam value="${data}"/>
                <sql:param value="${param.id_turma}"/>
            </sql:update>

        </c:when>
        <c:when test="${param.oper=='edit'}">
            <sql:update var="update" dataSource="jdbc/dbo_MicrosoftSQLServer">
                update calendarios
                set diautil_calendario=?, data_calendario=?
                where id_calendario=?                
                <sql:param value="${param.diautil_calendario}"/>
                <sql:dateParam value="${data}"/>
                <sql:param value="${param.id}"/>
            </sql:update>
        </c:when>
        <c:when test="${param.oper=='del'}">
            <sql:update var="update" dataSource="jdbc/dbo_MicrosoftSQLServer">
                delete from calendarios
                where id_calendario=?
                <sql:param value="${param.id}"/>
            </sql:update>
        </c:when>
    </c:choose>
</c:catch>
<c:if test = "${catchException!=null}">
    Erro : Não foi possível realizar a alteração.<br><br>
    <p  style="color:red">${fn:substringAfter(catchException,"BD:")} </p>    
</c:if>

